-module(rtps_sedp_eh).

%%% @doc The Simple Endpoint Discovery Protocol (SEDP) event manager
%%% is triggered on receiving a change in one of the available
%%% built-in endpoint discovery endpoints. Adding an event handler
%%% allows a user application, such as DDS, to take action on changes
%%% in the discovered endpoints.

-behaviour(gen_event).

-include_lib("kernel/include/logger.hrl").
-include("rtps.hrl").

%% API

%% gen_event callbacks
-export([init/1, handle_event/2, handle_call/2, 
	 handle_info/2, terminate/2, code_change/3]).

-record(data, {pid :: pid()}).

%%%===================================================================
%%% API
%%%===================================================================

%%%===================================================================
%%% gen_event callbacks
%%%===================================================================

%% @private
init([Pid | _Args]) ->
    {ok, #data{pid = Pid}}.

%% @private

%% Ignore events triggered when the process that installed the handler adds changes itself.
handle_event({add_change, {Pid, _Tag}, _Changes}, #data{pid = Pid} = Data) ->
    {ok, Data};
handle_event({add_change, {_Pid, _Tag} = _From, _Changes}, Data) ->
    %% [?LOG_INFO("From ~p, Change ~p~n", [Pid, Change]) || Change <- Changes],
    {ok, Data};
handle_event(_Event, Data) ->
    {ok, Data}.

%% @private
handle_call(_Request, Data) ->
    Reply = ok,
    {ok, Reply, Data}.

%% @private
handle_info(_Info, Data) ->
    {ok, Data}.

%% @private
terminate(_Reason, _Data) ->
    ok.

%% @private
code_change(_OldVsn, Data, _Extra) ->
    {ok, Data}.

%%%===================================================================
%%% Internal functions
%%%===================================================================

